<?php  if (!defined('PATH_HD')) exit('No direct script access allowed');

class IndexControl extends Control{
    function __auto(){
        C("debug",0);
        if(!isset($_SESSION['uid'])){

            go(__ROOT__."/index.php");
        }
    }
    function index(){
       $this->display();
    }
    // 右侧综合信息
    function right(){
        $db = M("user");
        $result = $db->find("userid=".$_SESSION['uid']);
        $this->assign("userinfo",$result);
    	$this->display();
    }

    function userInfo(){
        $db = M("user");
        $result = $db->find("userid=".$_SESSION['uid']);
        $this->assign("userinfo",$result);
    	$this->display();
    }

    function editUserInfo(){
        $db = M("user");
        $result = $db->where("userid=".$_SESSION['uid'])->save($_POST);
        if($result){
            $this->success("您的资料修改成功！","right");
        }else{
            $this->error("修改出错，请重试！");
        }
    }

    function addArc(){
        $db = M("category");
        $category = $db->where("issend<>0")->field("cid,catname")->all();
        $this->assign("category",$category);
        $this->display();
    }

    function arcPre(){
        
        $arcData = $_POST;
        $arcData['flag'] = 1;
        $arcData['addtime'] = time();
        $arcData['userid'] = $_SESSION['uid'];
        $db = M("arc");
        if($db->add($arcData)){
            $this->success("发表文章成功，请等待管理员审核!","userArcList");
        }
    }


    function userArcList(){
        $db = K("arc");
        $arc = $db->where("userid=".$_SESSION['uid'])->all();
        $this->assign("arc",$arc);
        $this->display();
    }

    function logOut(){
        session_unset();
        session_destroy();
        go(__ROOT__."/index.php");
    }
}
?>